package com.example.nginx.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.net.InetAddress;

@RestController
//如果用Controller，则需要写下面的ResponseBody，否则请求就转到html代码那儿了
@Controller
public class Control {

    @GetMapping("host")
//    @ResponseBody  返回字符串，如果不写这个，上面要用@RestController，
    public String host(){
        String host = null;
        try {
            host = InetAddress.getLocalHost().getHostName();
        }catch (Exception e){
            //打印堆栈信息
            e.printStackTrace();
        }
        return host;
    }

}
